﻿using System;
using System.Collections.Generic;
using System.Text;
using Torch.WL.Business.Interface;
using Torch.FrameWork.Utility;
using Torch.WL.Business.CleanChina;

namespace Torch.WL.Business
{
    public class CompanyProvider : BaseProvider<CompanyProvider.RequestDataInfo>, IDataProvider
    {
        public CompanyProvider(string _jsonInfo): base(_jsonInfo)
        {

        }

        public IMessageInfo Do()
        {
            IMessageInfo message = new MessageInfo();
            message.code = (int)MessageCodeType.Success;
            message.message = Utils.GetEnumDescription(MessageCodeType.Success);
            message.data = ProcessResponseData();

            return message;
            
        }

        private List<ResponseDataInfo> ProcessResponseData()
        {
            //use postdata.data to process responseData
            List<ResponseDataInfo> list = new List<ResponseDataInfo>();

            if (postdata == null || postdata.data == null)
                return list;
            
            list = TbCompanyManager.Instance().QueryCompanyByGroup(postdata.data.querykey, postdata.data.sortby);
            
            #region 虚拟数据
            /*
            ResponseDataInfo responseData = new ResponseDataInfo();

            responseData.firstchar = "a";
            responseData.company = new List<ResponseDataInfo.companyinfo>(); 
            ResponseDataInfo.companyinfo companyinf = new ResponseDataInfo.companyinfo();
            companyinf.companyid = 1;
            companyinf.companyname = "安阳清洁用品制造公司";
            responseData.company.Add(companyinf);

            companyinf = new ResponseDataInfo.companyinfo();
            companyinf.companyid = 2;
            companyinf.companyname = "安徽合肥公共用品制造公司";
            responseData.company.Add(companyinf);
            list.Add(responseData);

            responseData = new ResponseDataInfo();

            responseData.firstchar = "b";
            responseData.company = new List<ResponseDataInfo.companyinfo>();            

            companyinf = new ResponseDataInfo.companyinfo();
            companyinf.companyid = 3;
            companyinf.companyname = "北京清洁用品制造公司";
            responseData.company.Add(companyinf);

            companyinf = new ResponseDataInfo.companyinfo();
            companyinf.companyid = 4;
            companyinf.companyname = "北海清洁用品制造公司";
            responseData.company.Add(companyinf);     
       
            list.Add(responseData);
            */
#endregion

            return list;
        }

        public class RequestDataInfo 
        {
            public string querykey { get; set; }
            public int sortby { get; set; }
        }

        public class ResponseDataInfo
        {
            public string sectionname { get; set; }
            public List<companyinfo> company { get; set; }
                
            public class companyinfo
            { 
                public int companyid { get; set; }
                public string companyname { get; set; }
            }
        }

    }
}
